package com.hw.hcit.feature;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.provider.Settings;

import com.hw.hcit.conf.Config;
import com.hw.hcit.conf.JTestItem;

public class TouchView extends View {
	private static final float TOUCH_TOLERANCE = 4F;
	private static final int TOUCH_POINT_NUM_X = 12;
	private static final int TOUCH_POINT_NUM_Y = 20;
	private static final int TOUCH_POINT_WIDTH = 4;
	private int[] mTouchPointPositionX;
	private int[] mTouchPointPositionY;
	private boolean[] mTopLineDrawn;
	private boolean[] mBottomLineDrawn;
	private boolean[] mLeftLineDrawn;
	private boolean[] mRightLineDrawn;
	private boolean mFirstTestPass;
	private JTestItem mJTestItem;
	private Canvas mCanvas;
	private Bitmap mBitmap;
	private Paint mPaint;
	private int mScreenX;
	private int mScreenY;
	private int mBiasX;
	private int mBiasY;
	private float mX, mY;
	private Path mPath;
	private Paint mPathPaint;
	private Path mLinePath;
	private Paint mLinePathPaint;
	private boolean[] mTop;
	private boolean[] mBottom;
	private boolean[] mLeft;
	private boolean[] mRight;
	private boolean[] mHorizontal;
	private boolean[] mVertical;
	private boolean[] mLeftDiagonal;
	private boolean[] mRightDiagonal;
	private boolean mTopOutOfBounds;
	private boolean mBottomOutOfBounds;
	private boolean mLeftOutOfBounds;
	private boolean mRightOutOfBounds;
	private boolean mHOutOfBounds;
	private boolean mVOutOfBounds;
	private boolean mLOutOfBounds;
	private boolean mROutOfBounds;
	private boolean mTouchedDown;
	private String TAG = "TouchView";

	public static boolean isAllTrue(boolean... array) {
		for (boolean b : array)
			if (!b)
				return false;
		return true;
	}

	public void setJTestItem(JTestItem item) {
		mJTestItem = item;
	}

	protected void onDraw(Canvas canvas) {
		canvas.drawColor(Color.WHITE);
		Paint titlePaint = new Paint();
		titlePaint.setARGB(255, 0, 0, 0);
		titlePaint.setTextSize(30F);
		canvas.drawText("Touch screen test", mScreenX / 3, mScreenY / 2,
				titlePaint);
		Paint bitmapPaint = new Paint(Paint.DITHER_FLAG);
		canvas.drawBitmap(mBitmap, 0F, 0F, bitmapPaint);
		for (int i = 1; i < TOUCH_POINT_NUM_X - 1; i++) {
			// Top Line
			canvas.drawRect(mTouchPointPositionX[i], mBiasY,
					mTouchPointPositionX[i] + TOUCH_POINT_WIDTH, mBiasY
							+ TOUCH_POINT_WIDTH, bitmapPaint);
		}
		for (int i = 0; i < TOUCH_POINT_NUM_X; i++) {
			// Bottom Line
			canvas.drawRect(mTouchPointPositionX[i], mScreenY - mBiasY
					- TOUCH_POINT_WIDTH, mTouchPointPositionX[i]
					+ TOUCH_POINT_WIDTH, mScreenY - mBiasY, bitmapPaint);
		}
		for (int i = 0; i < TOUCH_POINT_NUM_Y - 1; i++) {
			// Left Line
			canvas.drawRect(mBiasX, mTouchPointPositionY[i], mBiasX
					+ TOUCH_POINT_WIDTH, mTouchPointPositionY[i]
					+ TOUCH_POINT_WIDTH, bitmapPaint);
			// Right Line
			canvas.drawRect(mScreenX - mBiasX, mTouchPointPositionY[i],
					mScreenX - mBiasX + TOUCH_POINT_WIDTH,
					mTouchPointPositionY[i] + TOUCH_POINT_WIDTH, bitmapPaint);
		}

		if (mFirstTestPass) {
			mCanvas.drawPath(mPath, mPathPaint);
		}
	}

	private void touch_start(float x, float y) {
		mPath.reset();
		mPath.moveTo(x, y);
		mX = x;
		mY = y;
	}

	private void touch_move(float x, float y) {
		float dx = Math.abs(x - mX);
		float dy = Math.abs(y - mY);
		if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
			mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
			mX = x;
			mY = y;
		}
	}

	private void touch_up() {
		mPath.lineTo(mX, mY);
		// commit the path to our offscreen
		mCanvas.drawPath(mPath, mPathPaint);
		// kill this so we don't double draw
		mPath.reset();
	}

	public boolean onTouchEvent(MotionEvent motionevent) {
		float motionX;
		float motionY;
		int screenX = mScreenX;
		int screenY = mScreenY;
		motionX = motionevent.getX();
		motionY = motionevent.getY();
		// Log.d(TAG, "motionX = " + motionX + " motionY = " + motionY);
		int action = motionevent.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			if (mFirstTestPass) {
				mTouchedDown = true;
				touch_start(motionX, motionY);
			}
			invalidate();
			break;
		case MotionEvent.ACTION_MOVE:
			float rectLeft = -1;
			float rectRight = -1;
			float rectTop = -1;
			float rectBottom = -1;
			for (int k = 0; k < TOUCH_POINT_NUM_X; k++) {
				if (motionX > screenX / TOUCH_POINT_NUM_X * k) {
					rectLeft = screenX / TOUCH_POINT_NUM_X * k;
					rectRight = screenX / TOUCH_POINT_NUM_X * (k + 1);
				}
			}
			for (int k = 0; k < TOUCH_POINT_NUM_Y; k++) {
				if (motionY > screenY / TOUCH_POINT_NUM_Y * k) {
					rectTop = screenY / TOUCH_POINT_NUM_Y * k;
					rectBottom = screenY / TOUCH_POINT_NUM_Y * (k + 1);
				}
			}
			Paint paint = mPaint;
			paint.setStyle(Paint.Style.FILL);
			paint.setColor(Color.RED);
			if ((rectLeft == 0 || rectTop == 0 || rectRight == mScreenX || rectBottom == mScreenY)
					&& !mFirstTestPass) {
				mCanvas.drawRect(rectLeft, rectTop, rectRight, rectBottom,
						paint);
				// invalidate();
				if (rectTop == 0) {
					// Top Line Drawn
					// Log.d(TAG, "rectLeft = " + rectLeft + " rectRight = "
					// + rectRight);
					for (int i = 0; i < TOUCH_POINT_NUM_X; i++) {
						if (rectLeft == mTouchPointPositionX[i] - mBiasX) {
							mTopLineDrawn[i] = true;
						}
					}
				}
				if (rectBottom == mScreenY) {
					// Bottom Line Drawn
					// Log.d(TAG, "rectLeft = " + rectLeft + " rectRight = "
					// + rectRight);
					for (int i = 0; i < TOUCH_POINT_NUM_X; i++) {
						if (rectLeft == mTouchPointPositionX[i] - mBiasX) {
							mBottomLineDrawn[i] = true;
						}
					}
				}
				if (rectLeft == 0) {
					// Left Line Drawn
					// Log.d(TAG, "rectTop = " + rectTop + " rectBottom = "
					// + rectBottom);
					for (int i = 0; i < TOUCH_POINT_NUM_Y; i++) {
						if (rectTop == mTouchPointPositionY[i] - mBiasY) {
							mLeftLineDrawn[i] = true;
						}
					}
				}
				if (rectRight == mScreenX) {
					// Right Line Drawn
					// Log.d(TAG, "rectTop = " + rectTop + " rectBottom = "
					// + rectBottom);
					for (int i = 0; i < TOUCH_POINT_NUM_Y; i++) {
						if (rectTop == mTouchPointPositionY[i] - mBiasY) {
							mRightLineDrawn[i] = true;
						}
					}
				}
			}

			boolean topLineDrawn = isAllTrue(mTopLineDrawn);
			boolean bottomLineDrawn = isAllTrue(mBottomLineDrawn);
			boolean leftLineDrawn = isAllTrue(mLeftLineDrawn);
			boolean rightLineDrawn = isAllTrue(mRightLineDrawn);

			// Log.d(TAG, "topLineDrawn = " + topLineDrawn);
			// Log.d(TAG, "bottomLineDrawn = " + bottomLineDrawn);
			// Log.d(TAG, "leftLineDrawn = " + leftLineDrawn);
			// Log.d(TAG, "rightLineDrawn = " + rightLineDrawn);
			if (!isAllTrue(mTop) && mFirstTestPass) {
				for (int i = 0; i < mTop.length; i++) {
					if (mScreenX / (mTop.length - 1) * i - 56 <= motionX
							&& motionX <= mScreenX / (mTop.length - 1)
									* i + 56
							&& motionY >= 0
							&& motionY <= mBiasY * 2) {
						mTop[i] = true;
					}
				}
				if (motionY <= 0 || motionY >= mBiasY * 2) {
					mTopOutOfBounds = true;
				}
			} else if (!isAllTrue(mBottom) && mFirstTestPass) {
				for (int i = 0; i < mBottom.length; i++) {
					if (mScreenX / (mBottom.length - 1) * i - 56 <= motionX
							&& motionX <= mScreenX / (mBottom.length - 1)
									* i + 56
							&& motionY >= mScreenY - mBiasY * 2
							&& motionY <= mScreenY) {
						mBottom[i] = true;
					}
				}
				if (motionY <= mScreenY - mBiasY * 2
						|| motionY >= mScreenY) {
					mBottomOutOfBounds = true;
				}
			} else if (!isAllTrue(mLeft) && mFirstTestPass) {
				for (int i = 0; i < mLeft.length; i++) {
					if (mScreenY / (mLeft.length - 1) * i - 72 <= motionY
							&& motionY <= mScreenY / (mLeft.length - 1) * i
									+ 72 && motionX >= 0
							&& motionX <= mBiasX * 2) {
						mLeft[i] = true;
					}
				}
				if (motionX <= 0 || motionX >= mBiasX * 2) {
					mLeftOutOfBounds = true;
				}
			} else if (!isAllTrue(mRight) && mFirstTestPass) {
				for (int i = 0; i < mRight.length; i++) {
					if (mScreenY / (mRight.length - 1) * i - 72 <= motionY
							&& motionY <= mScreenY / (mRight.length - 1) * i
									+ 72 && motionX >= mScreenX - mBiasX * 2
							&& motionX <= mScreenX) {
						mRight[i] = true;
					}
				}
				if (motionX <= mScreenX - mBiasX * 2 || motionX >= mScreenX) {
					mRightOutOfBounds = true;
				}
			} else if (!isAllTrue(mHorizontal) && mFirstTestPass) {
				for (int i = 0; i < mHorizontal.length; i++) {
					if (mScreenX / (mHorizontal.length - 1) * i - 56 <= motionX
							&& motionX <= mScreenX / (mHorizontal.length - 1)
									* i + 56
							&& motionY >= mScreenY / 2 - mBiasY
							&& motionY <= mScreenY / 2 + mBiasY) {
						mHorizontal[i] = true;
					}
				}
				if (motionY <= mScreenY / 2 - mBiasY
						|| motionY >= mScreenY / 2 + mBiasY) {
					mHOutOfBounds = true;
				}
			} else if (!isAllTrue(mVertical) && mFirstTestPass) {
				for (int i = 0; i < mVertical.length; i++) {
					if (mScreenY / (mVertical.length - 1) * i - 72 <= motionY
							&& motionY <= mScreenY / (mVertical.length - 1) * i
									+ 72 && motionX >= mScreenX / 2 - mBiasX
							&& motionX <= mScreenX / 2 + mBiasX) {
						mVertical[i] = true;
					}
				}
				if (motionX <= mScreenX / 2 - mBiasX
						|| motionX >= mScreenX / 2 + mBiasX) {
					mVOutOfBounds = true;
				}
			} else if (!isAllTrue(mLeftDiagonal) && mFirstTestPass) {
				float rX = (motionY + 50) * 693 / 1330;
				float distance = Math.abs(rX - motionX);
				// Log.d(TAG, "rX = " + rX + " distance = " + distance);
				for (int i = 0; i < mLeftDiagonal.length; i++) {
					if (distance < 46
							&& mScreenY / mLeftDiagonal.length * i <= motionY
							&& mScreenY / mLeftDiagonal.length * (i + 1) > motionY) {
						mLeftDiagonal[i] = true;
					}
				}
				if (distance > 46) {
					mLOutOfBounds = true;
				}
			} else if (!isAllTrue(mRightDiagonal) && mFirstTestPass) {
				float rX = mScreenX - (motionY + 50) * 693 / 1330;
				float distance = Math.abs(rX - motionX);
				// Log.d(TAG, "rX = " + rX + " distance = " + distance);
				for (int i = 0; i < mRightDiagonal.length; i++) {
					if (distance < 46
							&& mScreenY / mRightDiagonal.length * i <= motionY
							&& mScreenY / mRightDiagonal.length * (i + 1) > motionY) {
						mRightDiagonal[i] = true;
					}
				}
				if (distance > 46) {
					mROutOfBounds = true;
				}
			}
			/*
			 * for (int i = 0; i < mHorizontal.length; i++) { Log.d(TAG,
			 * "mHorizontal" + i + " = " + mHorizontal[i]); } for (int i = 0; i
			 * < mVertical.length; i++) { Log.d(TAG, "mVertical" + i + " = "
			 * + mVertical[i]); } for (int i = 0; i < mLeftDiagonal.length; i++)
			 * { Log.d(TAG, "mLeftDiagonal" + i + " = " + mLeftDiagonal[i]);
			 * } for (int i = 0; i < mRightDiagonal.length; i++) {
			 * Log.d(TAG, "mRightDiagonal" + i + " = " + mRightDiagonal[i]);
			 * } Log.d(TAG, "mHorizontal = " + isAllTrue(mHorizontal));
			 * Log.d(TAG, "mVertical = " + isAllTrue(mVertical));
			 * Log.d(TAG, "mLeftDiagonal = " + isAllTrue(mLeftDiagonal));
			 * Log.d(TAG, "mRightDiagonal = " + isAllTrue(mRightDiagonal));
			 * Log.d(TAG, "mHOutOfBounds = " + mHOutOfBounds);
			 * Log.d(TAG, "mVOutOfBounds = " + mVOutOfBounds);
			 * Log.d(TAG, "mLOutOfBounds = " + mLOutOfBounds);
			 * Log.d(TAG, "mROutOfBounds = " + mROutOfBounds);
			 */

			if (mFirstTestPass && mTouchedDown) {
				touch_move(motionX, motionY);
			}

			if (topLineDrawn && bottomLineDrawn && leftLineDrawn
					&& rightLineDrawn) {
				mFirstTestPass = true;
			}

			//if (isAllTrue(mHorizontal) && isAllTrue(mVertical)
			//		&& isAllTrue(mLeftDiagonal) && isAllTrue(mRightDiagonal)) {
			//	if (mJTestItem != null) {
			//		mJTestItem.testFinish(true, 1, true);
			//	}
			//}
			invalidate();
			break;
		case MotionEvent.ACTION_UP:
			touch_up();
			if (mFirstTestPass) {
				if (!isAllTrue(mTop) || mTopOutOfBounds) {
					Log.d(TAG, "mTop not All true!");
					drawTopLine();
					for (int i = 0; i < mTop.length; i++) {
						mTop[i] = false;
					}
					mTopOutOfBounds = false;
				} else if (!isAllTrue(mBottom) || mBottomOutOfBounds) {
					Log.d(TAG, "mBottom not All true!");
					drawBottomLine();
					for (int i = 0; i < mBottom.length; i++) {
						mBottom[i] = false;
					}
					mBottomOutOfBounds = false;
				} else if (!isAllTrue(mLeft) || mLeftOutOfBounds) {
					Log.d(TAG, "mLeft not All true!");
					drawLeftLine();
					for (int i = 0; i < mLeft.length; i++) {
						mLeft[i] = false;
					}
					mLeftOutOfBounds = false;
				} else if (!isAllTrue(mRight) || mRightOutOfBounds) {
					Log.d(TAG, "mRight not All true!");
					drawRightLine();
					for (int i = 0; i < mRight.length; i++) {
						mRight[i] = false;
					}
					mRightOutOfBounds = false;
				} else if (!isAllTrue(mHorizontal) || mHOutOfBounds) {
					Log.d(TAG, "mHorizontal not All true!");
					drawHorizontalLine();
					for (int i = 0; i < mHorizontal.length; i++) {
						mHorizontal[i] = false;
					}
					mHOutOfBounds = false;
				} else if (!isAllTrue(mVertical) || mVOutOfBounds) {
					Log.d(TAG, "mVertical not All true!");
					drawVerticalLine();
					for (int i = 0; i < mVertical.length; i++) {
						mVertical[i] = false;
					}
					mVOutOfBounds = false;
				} else if (!isAllTrue(mLeftDiagonal) || mLOutOfBounds) {
					Log.d(TAG, "mLeftDiagonal not All true!");
					drawLeftDiagonalLine();
					for (int i = 0; i < mLeftDiagonal.length; i++) {
						mLeftDiagonal[i] = false;
					}
					mLOutOfBounds = false;
				} else if (!isAllTrue(mRightDiagonal) || mROutOfBounds) {
					Log.d(TAG, "mRightDiagonal not All true!");
					drawRightDiagonalLine();
					for (int i = 0; i < mRightDiagonal.length; i++) {
						mRightDiagonal[i] = false;
					}
					mROutOfBounds = false;
				} else {
					if (mJTestItem != null) {
						setVisibility(View.GONE);
						Settings.System.putInt(Config.GetActivity().getContentResolver(), Settings.System.POINTER_LOCATION, 0);

					}
				}
			}
			invalidate();
			break;
		}
		return true;
	}

	private void drawTopLine() {
		mLinePath.reset();
		mLinePath.moveTo(0, 0);
		mLinePath.lineTo(mScreenX, 0);
		mLinePath.moveTo(0, mBiasY * 2);
		mLinePath.lineTo(mScreenX, mBiasY * 2);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawBottomLine() {
		mLinePath.reset();
		mLinePath.moveTo(0, mScreenY - mBiasY * 2);
		mLinePath.lineTo(mScreenX, mScreenY - mBiasY * 2);
		mLinePath.moveTo(0, mScreenY);
		mLinePath.lineTo(mScreenX, mScreenY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawHorizontalLine() {
		mLinePath.reset();
		mLinePath.moveTo(0, mScreenY / 2 - mBiasY);
		mLinePath.lineTo(mScreenX, mScreenY / 2 - mBiasY);
		mLinePath.moveTo(0, mScreenY / 2 + mBiasY);
		mLinePath.lineTo(mScreenX, mScreenY / 2 + mBiasY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawLeftLine() {
		mLinePath.reset();
		mLinePath.moveTo(0, 0);
		mLinePath.lineTo(0, mScreenY);
		mLinePath.moveTo(mBiasX * 2, 0);
		mLinePath.lineTo(mBiasX * 2, mScreenY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawRightLine() {
		mLinePath.reset();
		mLinePath.moveTo(mScreenX - mBiasX * 2, 0);
		mLinePath.lineTo(mScreenX - mBiasX * 2, mScreenY);
		mLinePath.moveTo(mScreenX, 0);
		mLinePath.lineTo(mScreenX, mScreenY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawVerticalLine() {
		mLinePath.reset();
		mLinePath.moveTo(mScreenX / 2 - mBiasX, 0);
		mLinePath.lineTo(mScreenX / 2 - mBiasX, mScreenY);
		mLinePath.moveTo(mScreenX / 2 + mBiasX, 0);
		mLinePath.lineTo(mScreenX / 2 + mBiasX, mScreenY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawLeftDiagonalLine() {
		mLinePath.reset();
		mLinePath.moveTo(mBiasX * 3, mBiasY);
		mLinePath.lineTo(mScreenX - mBiasX, mScreenY - mBiasY * 3);
		mLinePath.moveTo(mBiasX, mBiasY * 3);
		mLinePath.lineTo(mScreenX - mBiasX * 3, mScreenY - mBiasY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	private void drawRightDiagonalLine() {
		mLinePath.reset();
		mLinePath.moveTo(mScreenX - mBiasX * 3, mBiasY);
		mLinePath.lineTo(mBiasX, mScreenY - mBiasY * 3);
		mLinePath.moveTo(mScreenX - mBiasX, mBiasY * 3);
		mLinePath.lineTo(mBiasX * 3, mScreenY - mBiasY);
		mCanvas.drawColor(Color.WHITE);
		mCanvas.drawPath(mLinePath, mLinePathPaint);
		invalidate();
	}

	public void setSystemUiVisibility() {
		setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
				| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
				| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
				| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
				| View.SYSTEM_UI_FLAG_FULLSCREEN
				| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
	}

	public TouchView(Context context, AttributeSet attrs) {
		super(context, attrs);
		DisplayMetrics displaymetrics = new DisplayMetrics();
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		wm.getDefaultDisplay().getMetrics(displaymetrics);
		mScreenX = displaymetrics.widthPixels;
		// mScreenY = displaymetrics.heightPixels;
		mScreenY = 1280; // fix screen height because of navigation bar
		Log.d(TAG, "screen_X=" + mScreenX);
		Log.d(TAG, "screen_Y=" + mScreenY);
		mPaint = new Paint();
		mPaint.setAntiAlias(true);
		mPaint.setDither(true);
		android.graphics.Bitmap.Config config = android.graphics.Bitmap.Config.ARGB_8888;
		mBitmap = Bitmap.createBitmap(mScreenX, mScreenY, config);
		mCanvas = new Canvas(mBitmap);
		mTouchPointPositionX = new int[TOUCH_POINT_NUM_X];
		mTouchPointPositionY = new int[TOUCH_POINT_NUM_Y];
		mTopLineDrawn = new boolean[TOUCH_POINT_NUM_X];
		mBottomLineDrawn = new boolean[TOUCH_POINT_NUM_X];
		mRightLineDrawn = new boolean[TOUCH_POINT_NUM_Y];
		mLeftLineDrawn = new boolean[TOUCH_POINT_NUM_Y];
		mFirstTestPass = true;
		mBiasX = mScreenX / (2 * TOUCH_POINT_NUM_X);
		mBiasY = mScreenY / (2 * TOUCH_POINT_NUM_Y);
		for (int i = 0; i < TOUCH_POINT_NUM_X; i++) {
			mTouchPointPositionX[i] = mScreenX / TOUCH_POINT_NUM_X * i + mBiasX;
		}
		for (int i = 0; i < TOUCH_POINT_NUM_Y; i++) {
			mTouchPointPositionY[i] = mScreenY / TOUCH_POINT_NUM_Y * i + mBiasY;
		}
		mPath = new Path();
		mPathPaint = new Paint();
		mPathPaint.setAntiAlias(true);
		mPathPaint.setDither(true);
		mPathPaint.setColor(0xFFFF0000);
		mPathPaint.setStyle(Paint.Style.STROKE);
		mPathPaint.setStrokeJoin(Paint.Join.ROUND);
		mPathPaint.setStrokeCap(Paint.Cap.ROUND);
		mPathPaint.setStrokeWidth(5);
		mLinePath = new Path();
		mLinePathPaint = new Paint();
		mLinePathPaint.setAntiAlias(true);
		mLinePathPaint.setDither(true);
		mLinePathPaint.setColor(Color.GREEN);
		mLinePathPaint.setStyle(Paint.Style.STROKE);
		mLinePathPaint.setStrokeJoin(Paint.Join.ROUND);
		mLinePathPaint.setStrokeCap(Paint.Cap.ROUND);
		mLinePathPaint.setStrokeWidth(1);
		mTop = new boolean[5];
		mBottom = new boolean[5];
		mHorizontal = new boolean[5];
		mLeft = new boolean[8];
		mRight = new boolean[8];
		mVertical = new boolean[8];
		mLeftDiagonal = new boolean[8];
		mRightDiagonal = new boolean[8];
		mTopOutOfBounds = false;
		mBottomOutOfBounds = false;
		mLeftOutOfBounds = false;
		mRightOutOfBounds = false;
		mHOutOfBounds = false;
		mVOutOfBounds = false;
		mLOutOfBounds = false;
		mROutOfBounds = false;
		mTouchedDown = false;

                drawTopLine();
	}

}
